package com.timebank.volunteer.controller;

import com.timebank.common.core.constant.SecurityConstants;
import com.timebank.common.core.result.Result;
import com.timebank.common.core.web.controller.BaseController;
import com.timebank.common.core.web.page.TableDataInfo;
import com.timebank.common.core.web.pojo.AjaxResult;
import com.timebank.common.security.annotation.InnerAuth;
import com.timebank.volunteer.pojo.entity.VolunteerAttendList;
import com.timebank.volunteer.pojo.vo.VolunteerAttendListVO;
import com.timebank.volunteer.service.VolunteerAttendListService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 志愿服务 出席名单
 * @author shiliuyinzhen
 */
@RestController
@Api(tags = "志愿服务出席名单相关接口")
@RequestMapping("/attendList")
public class VolunteerAttendListController extends BaseController {

    @Resource
    private VolunteerAttendListService volunteerAttendListService;

    /**
     * 根据志愿服务Id获取出席名单
     * @param volunteerId
     * @return
     */
    @GetMapping("/list/{volunteerId}")
    @ApiOperation("获取出席名单")
    public TableDataInfo getAttendListByVolunteerId(@PathVariable("volunteerId") Long volunteerId){
        startPage();
        List<VolunteerAttendListVO> list = volunteerAttendListService.getAttendListByVolunteerId(volunteerId);
        return getDataTable(list);
    }

    /**
     * 批量删除出席名单
     * @param userIds
     * * @param map
     * @return
     */
    @DeleteMapping("/{userIds}")
    @ApiOperation("批量删除出席名单")
    public AjaxResult deleteAttendListByVolunteerIdAndUserIds(@PathVariable("userIds") Long[] userIds, @RequestBody Map<String,Long> map){
        Long volunteerId = map.get("volunteerId");
        return volunteerAttendListService.deleteAttendListByVolunteerIdAndUserIds(volunteerId,userIds);
    }

    /**
     * 批量添加出席名单
     * @param userIds
     * @param map
     * @return
     */
    @PostMapping("/{userIds}")
    @ApiOperation("批量添加出席名单")
    public AjaxResult batchInsertAttendList(@PathVariable("userIds") Long[] userIds, @RequestBody Map<String,Long> map){
        Long volunteerId = map.get("volunteerId");
        return volunteerAttendListService.batchInsertAttendList(volunteerId,userIds);
    }

    /**
     * 根据志愿服务Id查询志愿服务出席名单
     * @param volunteerId
     * @return
     */
    @InnerAuth
    @GetMapping("/{volunteerId}")
    public Result<List<VolunteerAttendListVO>> getVolunteerAttendListByVolunteerId(@PathVariable("volunteerId") Long volunteerId){
        List<VolunteerAttendListVO> list =
                volunteerAttendListService.getAttendListByVolunteerId(volunteerId);
        return Result.success(list);
    }

}
